package IniTester;

import inireader.*;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;

/**
 * @author Vladimír Matěna
 */
public class Example1
{
	public static void main(String[] args) throws SAXException, IOException,
			ParserConfigurationException
	{
		/**
		 * Example1
		 *
		 * This example show how to store some data in ini file without schema
		 * validation. This is usefull for saving config when no prevois config
		 * exist and you do not wan to create schema for your configuration.
		 */

		/**
		 * At the beginning we create new Configurator instance without schema.
		 * This will enable relaxed validation. All data will be intrpreted as
		 * strings.
		 */
		Configurator config = new Configurator();


		/**
		 * Now we have configuration, but it is emptyu. Let's add section to it.
		 * We have to create new identifier carying section name and use it to
		 * construct new section. Then we can add our firstSection to config.
		 */
		Section firstSection = new Section(new Identifier("Section1"), config);
		config.addSection(firstSection);


		/**
		 * We have section added to config. We can add some properties to this
		 * section. This code add two new properties to this section.
		 */
		Property firstProperty = new Property(
				new Identifier("Property1"),
				firstSection);
		firstSection.addProperty(firstProperty);

		Property secondProperty = new Property(
				new Identifier("Property2"),
				firstSection);
		firstSection.addProperty(secondProperty);


		/**
		 * Now we have config containing one section called "Section1" and two
		 * properties called "Property1" and "Property2". We can set values to
		 * them. This config do not use schema so this values will be stored
		 * as text.
		 */
		firstProperty.addElement(new Element("Text1", firstProperty));
		secondProperty.addElement(new Element("Text2", secondProperty));


		/**
		 * At this point configuration contins section two propeties and one
		 * value for each property. Let's store this configuration to file.
		 */
		config.saveINI("Example1.ini");
	}
}
